<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Cursor Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset='utf-8'>
	<meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1.0" />
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a name="//apple_ref/swift/Class/Cursor" class="dashAnchor"></a>
    <a title="Cursor Class Reference"></a>
    <header>
      <div class="content-wrapper">
        <p>
          <a href="../index.html">PostgresClientKit Docs</a>
          <span class="no-mobile"> (100% documented)</span>
        </p>
    
        <p class="header-right">
          <a href="https://github.com/codewinsdotcom/PostgresClientKit">
            <img src="../img/gh.png"/>
            <span class="no-mobile">View on GitHub</span>
          </a>
        </p>
    
      </div>
    </header>
    <div id="breadcrumbs-container">
      <div class="content-wrapper">
        <p id="breadcrumbs">
          <span class="no-mobile">
            <a href="../index.html">PostgresClientKit Reference</a>
            <img id="carat" src="../img/carat.png" />
          </span>
          Cursor Class Reference
        </p>
      </div>
    </div>
    <div class="wrapper">
      <div class="article-wrapper">
        <article class="main-content">
          <section>
            <section class="section">
              <h1>Cursor</h1>
                <div class="declaration">
                  <div class="language">
                    <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">Cursor</span> <span class="p">:</span> <span class="kt">Sequence</span><span class="p">,</span> <span class="kt">IteratorProtocol</span></code></pre>

                  </div>
                </div>
              <p>The result of successfully executing a <code><a href="../Classes/Statement.html">Statement</a></code>.</p>
<div class="aside aside-note">
    <p class="aside-title">Note</p>
    Do not confuse this <code>Cursor</code> class with the SQL cursors created by the <a href="https://www.postgresql.org/docs/12/sql-declare.html">SQL DECLARE
command</a>.  The <code>Cursor</code> class exposes
the result of executing a <em>single</em> SQL command.  A SQL cursor, on other other hand, exposes
a query&rsquo;s result by <em>repeated</em> execution of the SQL <code>FETCH</code> command.

</div>

<p>When a <code>Cursor</code> is no longer required, call <code><a href="../Classes/Cursor.html#/s:17PostgresClientKit6CursorC5closeyyF">Cursor.close()</a></code> to release its Postgres server
resources.  A <code>Cursor</code> is implicitly closed as a side effect of certain operations on a
connection; refer to the <code><a href="../Classes/Connection.html">Connection</a></code> documentation for a full list.  A <code>Cursor</code> is also
automatically closed by its deinitializer.</p>

<p>A <code>Cursor</code> in PostgresClientKit corresponds to the unnamed portal of the connection on the
Postgres server.</p>
<div class="aside aside-see-also">
    <p class="aside-title">See also</p>
    <a href="https://www.postgresql.org/docs/12/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY">Postgres: Message Flow - Extended
Query</a>

</div>

            </section>
            <section class="section task-group-section">
              <div class="task-group">
                <ul>
                  <li class="item">
                    <div>
                      <code>
                      <a name="/s:17PostgresClientKit6CursorC2idSSvp"></a>
                      <a name="//apple_ref/swift/Property/id" class="dashAnchor"></a>
                      <a class="token" href="#/s:17PostgresClientKit6CursorC2idSSvp">id</a>
                      </code>
                    </div>
                    <div class="height-container">
                      <div class="pointer-container"></div>
                      <section class="section">
                        <div class="pointer"></div>
                        <div class="abstract">
                          <p>Uniquely identifies this <code>Cursor</code>.</p>

<p>Used in logging and to formulate the <code><a href="../Classes/Cursor.html#/s:17PostgresClientKit6CursorC11descriptionSSvp">description</a></code>.</p>

                        </div>
                        <div class="declaration">
                          <h4>Declaration</h4>
                          <div class="language">
                            <p class="aside-title">Swift</p>
                            <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">let</span> <span class="nv">id</span><span class="p">:</span> <span class="kt">String</span></code></pre>

                          </div>
                        </div>
                      </section>
                    </div>
                  </li>
                  <li class="item">
                    <div>
                      <code>
                      <a name="/s:17PostgresClientKit6CursorC7columnsSayAA14ColumnMetadataVGSgvp"></a>
                      <a name="//apple_ref/swift/Property/columns" class="dashAnchor"></a>
                      <a class="token" href="#/s:17PostgresClientKit6CursorC7columnsSayAA14ColumnMetadataVGSgvp">columns</a>
                      </code>
                    </div>
                    <div class="height-container">
                      <div class="pointer-container"></div>
                      <section class="section">
                        <div class="pointer"></div>
                        <div class="abstract">
                          <p>Metadata about the columns in the results, or <code>nil</code> if column metadata is not available.</p>

<p>For column metadata to be available, set <code>retrieveColumnMetadata</code> to <code>true</code> in calling
<code><a href="../Classes/Statement.html#/s:17PostgresClientKit9StatementC7execute15parameterValues22retrieveColumnMetadataAA6CursorCSayAA0A16ValueConvertible_pSgG_SbtKF">Statement.execute(parameterValues:retrieveColumnMetadata:)</a></code>.</p>

<p>Each element in the returned value describes the corresponding element in the <code>columns</code>
of each <code><a href="../Structs/Row.html">Row</a></code> of the results.</p>

                        </div>
                        <div class="declaration">
                          <h4>Declaration</h4>
                          <div class="language">
                            <p class="aside-title">Swift</p>
                            <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">let</span> <span class="nv">columns</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Structs/ColumnMetadata.html">ColumnMetadata</a></span><span class="p">]?</span></code></pre>

                          </div>
                        </div>
                      </section>
                    </div>
                  </li>
                  <li class="item">
                    <div>
                      <code>
                      <a name="/s:17PostgresClientKit6CursorC9statementAA9StatementCvp"></a>
                      <a name="//apple_ref/swift/Property/statement" class="dashAnchor"></a>
                      <a class="token" href="#/s:17PostgresClientKit6CursorC9statementAA9StatementCvp">statement</a>
                      </code>
                    </div>
                    <div class="height-container">
                      <div class="pointer-container"></div>
                      <section class="section">
                        <div class="pointer"></div>
                        <div class="abstract">
                          <p>The <code><a href="../Classes/Statement.html">Statement</a></code> to which this <code>Cursor</code> belongs.</p>

                        </div>
                        <div class="declaration">
                          <h4>Declaration</h4>
                          <div class="language">
                            <p class="aside-title">Swift</p>
                            <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">let</span> <span class="nv">statement</span><span class="p">:</span> <span class="kt"><a href="../Classes/Statement.html">Statement</a></span></code></pre>

                          </div>
                        </div>
                      </section>
                    </div>
                  </li>
                  <li class="item">
                    <div>
                      <code>
                      <a name="/s:17PostgresClientKit6CursorC8rowCountSiSgvp"></a>
                      <a name="//apple_ref/swift/Property/rowCount" class="dashAnchor"></a>
                      <a class="token" href="#/s:17PostgresClientKit6CursorC8rowCountSiSgvp">rowCount</a>
                      </code>
                    </div>
                    <div class="height-container">
                      <div class="pointer-container"></div>
                      <section class="section">
                        <div class="pointer"></div>
                        <div class="abstract">
                          <p>The number of rows affected by the <code><a href="../Classes/Statement.html">Statement</a></code>.</p>

<p>The specific interpretation of this value depends on the SQL command performed:</p>

<ul>
<li><code>INSERT</code>: the number of rows inserted</li>
<li><code>UPDATE</code>: the number of rows updated</li>
<li><code>DELETE</code>: the number of rows deleted</li>
<li><code>SELECT</code> or <code>CREATE TABLE AS</code>: the number of rows retrieved</li>
<li><code>MOVE</code>: the number of rows by which the SQL cursor&rsquo;s position changed</li>
<li><code>FETCH</code>: the number of rows retrieved from the SQL cursor</li>
<li><code>COPY</code>: the number of rows copied</li>
</ul>

<p>If this <code>Cursor</code> has one or more rows, this property is <code>nil</code> until the final row has been
retrieved (in other words, until <code><a href="../Classes/Cursor.html#/s:17PostgresClientKit6CursorC4nexts6ResultOyAA3RowVs5Error_pGSgyF">next()</a></code> returns <code>nil</code>).</p>

                        </div>
                        <div class="declaration">
                          <h4>Declaration</h4>
                          <div class="language">
                            <p class="aside-title">Swift</p>
                            <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">internal(set)</span> <span class="k">var</span> <span class="nv">rowCount</span><span class="p">:</span> <span class="kt">Int</span><span class="p">?</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                          </div>
                        </div>
                      </section>
                    </div>
                  </li>
                  <li class="item">
                    <div>
                      <code>
                      <a name="/s:17PostgresClientKit6CursorC8isClosedSbvp"></a>
                      <a name="//apple_ref/swift/Property/isClosed" class="dashAnchor"></a>
                      <a class="token" href="#/s:17PostgresClientKit6CursorC8isClosedSbvp">isClosed</a>
                      </code>
                    </div>
                    <div class="height-container">
                      <div class="pointer-container"></div>
                      <section class="section">
                        <div class="pointer"></div>
                        <div class="abstract">
                          <p>Whether this <code>Cursor</code> is closed.</p>

<p>To close a <code>Cursor</code>, call <code><a href="../Classes/Cursor.html#/s:17PostgresClientKit6CursorC5closeyyF">close()</a></code>.</p>

                        </div>
                        <div class="declaration">
                          <h4>Declaration</h4>
                          <div class="language">
                            <p class="aside-title">Swift</p>
                            <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">isClosed</span><span class="p">:</span> <span class="kt">Bool</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                          </div>
                        </div>
                      </section>
                    </div>
                  </li>
                  <li class="item">
                    <div>
                      <code>
                      <a name="/s:17PostgresClientKit6CursorC5closeyyF"></a>
                      <a name="//apple_ref/swift/Method/close()" class="dashAnchor"></a>
                      <a class="token" href="#/s:17PostgresClientKit6CursorC5closeyyF">close()</a>
                      </code>
                    </div>
                    <div class="height-container">
                      <div class="pointer-container"></div>
                      <section class="section">
                        <div class="pointer"></div>
                        <div class="abstract">
                          <p>Closes this <code>Cursor</code>.</p>

<p>Has no effect if this <code>Cursor</code> is already closed.</p>

                        </div>
                        <div class="declaration">
                          <h4>Declaration</h4>
                          <div class="language">
                            <p class="aside-title">Swift</p>
                            <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">close</span><span class="p">()</span></code></pre>

                          </div>
                        </div>
                      </section>
                    </div>
                  </li>
                </ul>
              </div>
              <div class="task-group">
                <div class="task-name-container">
                  <a name="/IteratorProtocol"></a>
                  <a name="//apple_ref/swift/Section/IteratorProtocol" class="dashAnchor"></a>
                  <a href="#/IteratorProtocol">
                    <h3 class="section-name">IteratorProtocol</h3>
                  </a>
                </div>
                <ul>
                  <li class="item">
                    <div>
                      <code>
                      <a name="/s:17PostgresClientKit6CursorC4nexts6ResultOyAA3RowVs5Error_pGSgyF"></a>
                      <a name="//apple_ref/swift/Method/next()" class="dashAnchor"></a>
                      <a class="token" href="#/s:17PostgresClientKit6CursorC4nexts6ResultOyAA3RowVs5Error_pGSgyF">next()</a>
                      </code>
                    </div>
                    <div class="height-container">
                      <div class="pointer-container"></div>
                      <section class="section">
                        <div class="pointer"></div>
                        <div class="abstract">
                          <p>Gets the next <code><a href="../Structs/Row.html">Row</a></code> of this <code>Cursor</code>.</p>

<p>Example of use:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">cursor</span><span class="p">:</span> <span class="kt">Cursor</span> <span class="o">=</span> <span class="o">...</span>
<span class="k">for</span> <span class="n">row</span> <span class="k">in</span> <span class="n">cursor</span> <span class="p">{</span>
    <span class="k">let</span> <span class="nv">columns</span> <span class="o">=</span> <span class="k">try</span> <span class="n">row</span><span class="o">.</span><span class="nf">get</span><span class="p">()</span><span class="o">.</span><span class="n">columns</span> <span class="c1">// throws upon an error</span>
    <span class="o">...</span>
<span class="p">}</span>
</code></pre>

                        </div>
                        <div class="declaration">
                          <h4>Declaration</h4>
                          <div class="language">
                            <p class="aside-title">Swift</p>
                            <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">next</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Result</span><span class="o">&lt;</span><span class="kt"><a href="../Structs/Row.html">Row</a></span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">?</span></code></pre>

                          </div>
                        </div>
                        <div>
                          <h4>Return Value</h4>
                          <p>a value that represents success (with an associated <code><a href="../Structs/Row.html">Row</a></code>) or failure (with
an associated <code>Error</code>); or <code>nil</code> if there are no more rows</p>
                        </div>
                      </section>
                    </div>
                  </li>
                </ul>
              </div>
              <div class="task-group">
                <div class="task-name-container">
                  <a name="/CustomStringConvertible"></a>
                  <a name="//apple_ref/swift/Section/CustomStringConvertible" class="dashAnchor"></a>
                  <a href="#/CustomStringConvertible">
                    <h3 class="section-name">CustomStringConvertible</h3>
                  </a>
                </div>
                <ul>
                  <li class="item">
                    <div>
                      <code>
                      <a name="/s:17PostgresClientKit6CursorC11descriptionSSvp"></a>
                      <a name="//apple_ref/swift/Property/description" class="dashAnchor"></a>
                      <a class="token" href="#/s:17PostgresClientKit6CursorC11descriptionSSvp">description</a>
                      </code>
                    </div>
                    <div class="height-container">
                      <div class="pointer-container"></div>
                      <section class="section">
                        <div class="pointer"></div>
                        <div class="abstract">
                          <p>A short string that identifies this <code>Cursor</code>.</p>

                        </div>
                        <div class="declaration">
                          <h4>Declaration</h4>
                          <div class="language">
                            <p class="aside-title">Swift</p>
                            <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">description</span><span class="p">:</span> <span class="kt">String</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                          </div>
                        </div>
                      </section>
                    </div>
                  </li>
                </ul>
              </div>
            </section>
          </section>
        </article>
      </div>
      <div class="nav-wrapper">
        <nav class="nav-bottom">
          <ul class="nav-groups">
            <li class="nav-group-name">
              <a href="../Classes.html">Classes</a>
              <ul class="nav-group-tasks">
                <li class="nav-group-task">
                  <a href="../Classes/Connection.html">Connection</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Classes/ConnectionPool.html">ConnectionPool</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Classes/ConsoleLogHandler.html">ConsoleLogHandler</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Classes/Cursor.html">Cursor</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Classes/Logger.html">Logger</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Classes/Statement.html">Statement</a>
                </li>
              </ul>
            </li>
            <li class="nav-group-name">
              <a href="../Enums.html">Enumerations</a>
              <ul class="nav-group-tasks">
                <li class="nav-group-task">
                  <a href="../Enums/Credential.html">Credential</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Enums/LogLevel.html">LogLevel</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Enums/PostgresError.html">PostgresError</a>
                </li>
              </ul>
            </li>
            <li class="nav-group-name">
              <a href="../Extensions.html">Extensions</a>
              <ul class="nav-group-tasks">
                <li class="nav-group-task">
                  <a href="../Extensions/Bool.html">Bool</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Extensions/Date.html">Date</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Extensions/Decimal.html">Decimal</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Extensions/Double.html">Double</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Extensions/Int.html">Int</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Extensions/Optional.html">Optional</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Extensions/String.html">String</a>
                </li>
              </ul>
            </li>
            <li class="nav-group-name">
              <a href="../Protocols.html">Protocols</a>
              <ul class="nav-group-tasks">
                <li class="nav-group-task">
                  <a href="../Protocols/ConnectionDelegate.html">ConnectionDelegate</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Protocols/LogHandler.html">LogHandler</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Protocols/PostgresValueConvertible.html">PostgresValueConvertible</a>
                </li>
              </ul>
            </li>
            <li class="nav-group-name">
              <a href="../Structs.html">Structures</a>
              <ul class="nav-group-tasks">
                <li class="nav-group-task">
                  <a href="../Structs/ColumnMetadata.html">ColumnMetadata</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/ConnectionConfiguration.html">ConnectionConfiguration</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/ConnectionPoolConfiguration.html">ConnectionPoolConfiguration</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/ConnectionPoolMetrics.html">ConnectionPoolMetrics</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/LogRecord.html">LogRecord</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/Notice.html">Notice</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/Postgres.html">Postgres</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/PostgresByteA.html">PostgresByteA</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/PostgresDate.html">PostgresDate</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/PostgresTime.html">PostgresTime</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/PostgresTimeWithTimeZone.html">PostgresTimeWithTimeZone</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/PostgresTimestamp.html">PostgresTimestamp</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/PostgresTimestampWithTimeZone.html">PostgresTimestampWithTimeZone</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/PostgresValue.html">PostgresValue</a>
                </li>
                <li class="nav-group-task">
                  <a href="../Structs/Row.html">Row</a>
                </li>
              </ul>
            </li>
          </ul>
        </nav>
      </div>
      <div class="footer-wrapper">
        <section id="footer">
          <p>Copyright 2019 David Pitfield and the PostgresClientKit contributors. Licensed under the Apache License, Version 2.0.</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </div>
    </div>
  </body>
</div>
</html>
